<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>个人信息</title>
    <link rel="stylesheet" type="text/css" href="../../css/api.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/register-edit.css" />
</head>
<body>

	<div id="wrap">
		<div id="main">
		
			<div class="register-edit">
				
				<img id="register-edit-avatar" onclick="uploadAvatar()" src="../../image/icon-camera.png" class="register-edit-avatar" />
				
				<div class="block-register-edit">
					<div class="block-register-title">昵称</div>
					<input class="input-block-register" placeholder="不超过6个字" id="name" />
				</div>
				
				<div class="block-register-edit">
					<div class="block-register-title">选择城市</div>
					<div class="block-register-city-selector">请选择城市</div>
				</div>
				
				
				<div class="register-edit-btn" onclick="finishRegisterEdit()">下一步</div>
				
			</div>	
	
		</div>
	</div>
	
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/common.js"></script>
<script type="text/javascript">
	apiready = function(){
		
	};
	
	function uploadAvatar() {
		api.getPicture({
        		sourceType: 'library',
	        encodingType: 'png',
	        mediaValue: 'pic',
	        destinationType: 'url',
	        allowEdit: false,
	        quality: 30,
        },function(ret,err){
        		
        		if (ret) {
        			
        			api.showProgress({
        				title: '正在上传头像...',
        				modal: false
    				});
    				
    				uploadImage(ret.data, function(ret, err) {
    				
	        			if (ret) {
		        			if (ret.path) {
		        				alert(ret.path);
		        				$api.attr($api.byId('register-edit-avatar'), 'src', ret.path);
		        			}		
		        			
		        			$api.setStorage("create-user-avatar", ret.path);
	
		        			api.hideProgress();
	        			} else {
	        				alert(err.msg);
	        				
	        				api.hideProgress();
	        			}
	        		});
        			
        		} else {
        			api.alert({msg:err.msg});
        		}
        		
        });
	}
	
	function finishRegisterEdit() {
		
		var name = $api.byId('name').value;
		
		if (name == '') {
			api.toast({
	            msg:'请输入昵称！'
            });
			return false;
		} 
		
		if (!$api.getStorage('create-user-avatar')) {
			api.toast({
	            msg:'请上传头像'
            });
            return false;
		}
		
		$api.setStorage('create-user-name',name);
		
		api.openWin({
	        name: 'register-tags',
        		url: '../register-tags/register-tags.html',
        		opaque: true,
        		vScrollBarEnabled: false
        });
	
	}
	
</script>
</html>